﻿using System;
using System.Runtime.InteropServices;

namespace WinwiseARDrone.API
{
    [StructLayout(LayoutKind.Sequential)]
    public struct Input_Device
    {
        public static Input_Device Input = new Input_Device("test", new DroneInput(DroneController.DroneInput.OpenInput),
            new DroneInput(DroneController.DroneInput.UpdateInput), new DroneInput(DroneController.DroneInput.CloseInput));

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = Constants.MAX_NAME_LENGTH)]
        public string name;

        [MarshalAs(UnmanagedType.FunctionPtr)]
        public DroneInput Open;

        [MarshalAs(UnmanagedType.FunctionPtr)]
        public DroneInput Update;

        [MarshalAs(UnmanagedType.FunctionPtr)]
        public DroneInput Close;

        public Input_Device(string pName, DroneInput pOpen, DroneInput pUpdate, DroneInput pClose)
        {
            this.name = pName;

            this.Open = pOpen;
            this.Update = pUpdate;
            this.Close = pClose;
        }
    }

    public struct navdata_demo_t
    {
        public UInt16 tag;
        public UInt16 size;

        // instance of #def_ardrone_state_mask_t
        public UInt32 ctrl_state;

        // battery voltage filtered (mV)
        public UInt32 vbat_flying_percentage;

        //UAV's attitude
        public float theta;

        // UAV's attitude
        public float phi;

        // UAV's attitude
        public float psi;

        // UAV's altitude
        public Int32 altitude;

        // UAV's estimated linear velocity
        public float vx;
        // UAV's estimated linear velocity        
        public float vy;
        // UAV's estimated linear velocity
        public float vz;

        // streamed frame index
        public UInt32 num_frames;			 

        // Camera parameters compute by detection
        public matrix33_t detection_camera_rot; /*!<  Deprecated ! Don't use ! */
        public vector31_t detection_camera_trans; /*!<  Deprecated ! Don't use ! */
        public UInt32 detection_tag_index; /*!<  Deprecated ! Don't use ! */
        public UInt32 detection_camera_type; /*!<  Deprecated ! Don't use ! */

        // Camera parameters compute by drone
        public matrix33_t drone_camera_rot;
        public vector31_t drone_camera_trans;
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct matrix33_t
    {
        float m11;
        float m12;
        float m13;
        float m21;
        float m22;
        float m23;
        float m31;
        float m32;
        float m33;
    }

    [StructLayout(LayoutKind.Explicit)]
    public struct vector31_t
    {
        [FieldOffset(0)]
        IntPtr v;

        [FieldOffset(0)]   
        public Point p;

        [StructLayout(LayoutKind.Sequential)]
        public struct Point
        {
            float x;
            float y;
            float z;
        }
    }
}
